package com.neutech.view;

import com.neutech.dao.BusinessDAO;
import com.neutech.dao.FoodDAO;
import com.neutech.dao.impl.BusinessDAOImpl;
import com.neutech.dao.impl.FoodDAOImpl;
import com.neutech.entity.Business;
import com.neutech.entity.Food;

import java.math.BigDecimal;
import java.util.List;

import static com.neutech.constant.Constant.input;
import static com.neutech.view.FoodView.*;

public class BusinessView {
    private static BusinessDAO businessDAO = new BusinessDAOImpl();
    public static void showMeau(){
        System.out.println("1.查看商家所有信息");
        System.out.println("2.增加商家");
        System.out.println("3.修改商家");
        System.out.println("4.删除商家");
        System.out.println("5.查看所有食品信息");
        System.out.println("6.增加食品信息");
        System.out.println("7.修改食品信息");
        System.out.println("8.删除食品");
        System.out.println("9.回到上级菜单");
        System.out.println("请输入编号选择功能");
        int index =input.nextInt();
        if (index==1){
            showBussinesses();

        }else if (index==2) {

            increaseBusinesses();

        }else if (index==3) {

//            增加
            modifyBusinesses();

        }else if (index==4) {

            putBusinesses();

        }else if (index==5) {

            FoodView.showFoodAll();

        }else if (index==6) {

            insertFood();



        }else if (index==7) {

            modifyFood();

        }else if (index==8) {

            putFood();

        }
        else if (index==9) {

            AdminView.showMeau();
            
        }
    }
    
    public static void showBussinesses(){
        //TODO 查询数据库展示商家信息
//        AdminDAO admin1 =new AdminDAOImpl();
        List<Business> businessList = businessDAO.selectAll();
        if (businessList.size() == 0){
            System.out.println("没有商家数据");
        }else {
            for (Business business : businessList) {
                System.out.println(business);

            }
        }

        showMeau();
    }
    public static void increaseBusinesses(){
        System.out.println("请输入商家编号");
        String businessId=input.next();
        System.out.println("请输入密码");
        String password=input.next();
        System.out.println("请输入商家名称");
        String businessName=input.next();
        System.out.println("请输入商家地址");
        String businessAddress=input.next();
        System.out.println("请输入商家介绍");
        String businessExplain=input.next();
        System.out.println("请输入起送费");
        BigDecimal starPrice=input.nextBigDecimal();
        System.out.println("请输入配送费");
        BigDecimal deliveryPrice=input.nextBigDecimal();
        Business business=new Business();
        business.setBusinessId(Integer.valueOf(businessId));
        business.setPassword(password);
        business.setBusinessName(businessName);
        business.setBusinessAddress(businessAddress);
        business.setBusinessExplain(businessExplain);
        business.setStartPrice(starPrice);
        business.setDeliveryPrice(deliveryPrice);
        businessDAO.insert(business);
        System.out.println("增加成功");
        showMeau();
    }

    public static void modifyBusinesses(){
        System.out.println("请输入商家名");
        String businessNameDate=input.next();
        Business business=businessDAO.selectBybusinessName(businessNameDate);
        if(business.getBusinessId()==null){
            System.out.println("无此商家号");
        }else
        {
            businessDAO.delete(business);
            System.out.println("请输入商家编号");
            String businessId=input.next();
            System.out.println("请输入密码");
            String password=input.next();
            System.out.println("请输入商家名称");
            String businessName=input.next();
            System.out.println("请输入商家地址");
            String businessAddress=input.next();
            System.out.println("请输入商家介绍");
            String businessExplain=input.next();
            System.out.println("请输入起送费");
            BigDecimal starPrice=input.nextBigDecimal();
            System.out.println("请输入配送费");
            BigDecimal deliveryPrice=input.nextBigDecimal();
            business.setBusinessId(Integer.valueOf(businessId));
            business.setPassword(password);
            business.setBusinessName(businessName);
            business.setBusinessAddress(businessAddress);
            business.setBusinessExplain(businessExplain);
            business.setStartPrice(starPrice);
            business.setDeliveryPrice(deliveryPrice);
            businessDAO.update(business);
            System.out.println("修改成功");}
            showMeau();
    }
    public static void putBusinesses(){
        System.out.println("请输入要删除的商家名称");
        String businessName= input.next();
        Business business=businessDAO.selectBybusinessName(businessName);
        if(business.getBusinessId()==null){
            System.out.println("没有此商户");
            showMeau();
        }
        else{
            business.setBusinessId(business.getBusinessId());
            businessDAO.delete(business);
            System.out.println("删除成功");
            showMeau();
        }

    }


}
